/*******************************************************************************
 * Copyright (c) 2016 Avaloq Group AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Avaloq Group AG - initial API and implementation
 *******************************************************************************/

package com.avaloq.tools.ddk.xtext.resource;

import java.util.Set;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.util.IAcceptor;


/**
 * Abstract implementation of API aggregation for export extensions,
 * so in actual extension implementations one has to only inject services
 * generated out of extension export file.
 * <p>
 * Implementations of this abstract class are generated by Export DSL
 * when used with "export extension" clause.
 * </p>
 */
public abstract class AbstractExportFeatureExtension implements IExportFeatureExtension {

  @Override
  public QualifiedName qualifiedName(final EObject object) {
    return getNamesProvider().getFullyQualifiedName(object);
  }

  @Override
  public String computeFingerprint(final EObject object) {
    return getFingerprintComputer().computeFingerprint(object);
  }

  @Override
  public boolean appendFragmentSegment(final EObject object, final StringBuilder builder) {
    return getFragmentProvider().appendFragmentSegment(object, builder);
  }

  @Override
  public Set<EClass> getExportedEClasses(final Resource resource) {
    return getResourceDescriptionStrategy().getExportedEClasses(resource);
  }

  @Override
  public boolean createEObjectDescriptions(final EObject object, final IAcceptor<IEObjectDescription> acceptor) {
    return getResourceDescriptionStrategy().doCreateEObjectDescriptions(object, acceptor);
  }

  /**
   * Gets the names provider.
   *
   * @return the names provider, must not be {@code null}
   */
  protected abstract IQualifiedNameProvider getNamesProvider();

  /**
   * Gets the fingerprint computer.
   *
   * @return the fingerprint computer, must not be {@code null}
   */
  protected abstract IFingerprintComputer getFingerprintComputer();

  /**
   * Gets the fragment provider.
   *
   * @return the fragment provider, must not be {@code null}
   */
  protected abstract AbstractSelectorFragmentProvider getFragmentProvider();

  /**
   * Gets the resource description strategy.
   *
   * @return the resource description strategy, must not be {@code null}
   */
  protected abstract AbstractResourceDescriptionStrategy getResourceDescriptionStrategy();

}
